package com.kdd.campus.pay.service.impl;

import com.github.wxpay.sdk.WXPayUtil;
import com.kdd.campus.common.util.HttpClientUtil;
import com.kdd.campus.pay.service.PayService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: fcp
 * @Date: 2020/5/18 10:55
 * @Description:
 */
@Service
public class PayServiceImpl implements PayService {
    @Override
    public String generatePaymentCode(String totalFee, String outTradeNo) throws Exception {
        // Map转成XML字符串
        Map<String, String> map = new HashMap<>();
        map.put("appid", "wx8397f8696b538317");
        map.put("mch_id", "1473426802");
        map.put("nonce_str", WXPayUtil.generateNonceStr());
        map.put("body", "大哥出品，必是精品");
        map.put("out_trade_no", outTradeNo);
        map.put("total_fee",totalFee);
        map.put("notify_url", "http://31q62n7636.zicp.vip/pay/notify");
        map.put("spbill_create_ip","127.0.0.1");
        map.put("trade_type","NATIVE");//交易类型
        String xml = WXPayUtil.generateSignedXml(map,"T6m9iK73b0kn9g5v426MKfHQH7X8rKwb");
        String result = HttpClientUtil.doPostByXml("https://api.mch.weixin.qq.com/pay/unifiedorder", xml);
        Map<String, String> toMap = WXPayUtil.xmlToMap(result);
        return toMap.get("code_url");
    }

    @Override
    public String queryOrder() {
        return null;
    }
}
